﻿using Dapper;
using MySql.Data.MySqlClient;
using Net1.My.Web.Models;
using Net1.My.Web.Models.DB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Net1.My.Web.DAL
{
    public class DAL_css
    {
        private MySqlConnection mySqlConnection = new MySqlConnection(ConfigHelper.Configuration["MySQLConnectionString1"]);
        /// <summary>
        /// 返回对应id的一条学生数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public css single(int id)
        {
            var single = mySqlConnection.QueryFirstOrDefault<css>("select * from classes join students on classes.id = students.class_id join scores on students.id = scores.student_id where id =@id", new { id });
            return single;
        }
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        public List<css> getclassss()
        {
            var list = mySqlConnection.Query<css>("select * from classes join students on classes.id = students.class_id join scores on students.id = scores.student_id").ToList();
            return list;
        }
        public List<css> getcss(string likestr)
        {
            var list = mySqlConnection.Query<css>($"select * from classes join students on classes.id = students.class_id join scores on students.id = scores.student_id " +
                $"where class_name like '%{likestr}%'or  major_name like '%{likestr}%' or student_name like '%{likestr}%'or class_id like '%{likestr}%' or student_id like '%{likestr}%' or course_name like '%{likestr}%'" +
                $" or check_sum like '%{likestr}%'or  `check` like '%{likestr}%'or score like '%{likestr}%' ").ToList();
            return list;
        }
    }
}
